﻿using Microsoft.Extensions.Hosting;
using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Rds.Second
{
    public class ReceiveMsgBgTask : BackgroundService
    {
        ConnectionMultiplexer redis;
        IDatabase db;
        ISubscriber sub;
        CancellationTokenSource cts;
        public ReceiveMsgBgTask()
        {
            redis = ConnectionMultiplexer.Connect("localhost");
            db = redis.GetDatabase();
            sub = redis.GetSubscriber();
            cts = new CancellationTokenSource(TimeSpan.FromMinutes(3));
        }
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            sub.Subscribe("messages", (channel, message) =>
            {
                Console.WriteLine((string)message);
            }); 
        }
    }
}
